package com.wjf.userservice.mapper;

import com.wjf.userservice.entity.Role;
import com.wjf.userservice.entity.Permission;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface RoleMapper {
    
    /**
     * 根据用户ID查询用户的所有角色
     */
    @Select("SELECT r.* FROM role r " +
            "INNER JOIN user_role ur ON r.id = ur.role_id " +
            "WHERE ur.user_id = #{userId}")
    List<Role> findRolesByUserId(Long userId);
    
    /**
     * 根据角色ID查询角色的所有权限
     */
    @Select("SELECT p.* FROM permission p " +
            "INNER JOIN role_permission rp ON p.id = rp.permission_id " +
            "WHERE rp.role_id = #{roleId}")
    List<Permission> findPermissionsByRoleId(Long roleId);


    
    @Select("SELECT p.* FROM permission p " +
        "INNER JOIN role_permission rp ON p.id = rp.permission_id " +
        "INNER JOIN user_role ur ON rp.role_id = ur.role_id " +
        "WHERE ur.user_id = #{userId} AND p.status = 1")
    List<Permission> findPermissionsByUserId(Long userId);
} 